package com.config;


import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect//描述一个切面类，定义切面类的时候需要打上这个注解
@Component
public class SpringAop {
    Logger logg=Logger.getLogger(getClass());
    //整个Controller目录的拦截
    //@Pointcut("execution(* com.controller.*.*(..))")
    //单个Controller文件的拦截
    @Pointcut("execution(* com.controller.Hello*.*(..))")
    public void qieru(){
    	
    }
    @Around("qieru()")
    public String huanrao(ProceedingJoinPoint poin) throws Throwable{
        System.out.println("环绕通知"+logg.getClass().getName());
        poin.proceed();
        return "Welcome to use AOP";
    }
    @Before("qieru()")
    public void qianzhi(){
        System.out.println("前置通知");
    }
    @After("qieru()")
    public void houzhi(){
        System.out.println("后置通知");
    }

    @AfterReturning("qieru()")
    public void qianzhifanhui(){
        System.out.println("后置返回 ");
    }
    @AfterThrowing("qieru()")
    public void qianzhiYichang(){
        System.out.println("后置异常");
    }

}